#pragma once
#include "Cache.h"

class NBDCache : public Cache
{
public:
    enum class LineState
    {
        None,
        Valid,
        Dirty
    };
    typedef struct
    {
        word_t tag;
        LineState state;
    } Meta;

private:
    word_t m_line_size;
    word_t m_way_num;

    word_t m_tag_mask;
    word_t m_index_mask;
    word_t m_offset_mask;

    word_t m_offset_padding;
    word_t m_index_padding;
    word_t m_tag_padding;

    Meta **metas;

    struct
    {
        bool meta_port_busy;
    } state = {0};
public:
    NBDCache();
    void run() override;
    void reset() override;
    bool send(CacheOP *cop) override;

private:
    void Stage1();
    void Stage2();
    void Stage3();
};
